import { emptyHandle, timestampToTime } from '@vc/utils';
import type { IColumnsOption } from 'vc';
import { INDEX, renderFileJump } from '@/utils/tableColumn';

export function useTable() {
  
  const columns = ref<Nullable<IColumnsOption>[]>([
    { ...INDEX },
    {
      width: 120,
      field: 'eventDate',
      title: '发生时间',
      align: 'center',
      formatter: ({ row }) => {
        return emptyHandle(timestampToTime(row.eventDate));
      }
    },
    {
      width: 120,
      field: 'eventTypeLabels',
      title: '事件类型',
      headerAlign: 'center',
      align: 'center',
      slots: {
        default: ({ row }) => {
          return row?.eventTypeLabels?.length ? <span>{row.eventTypeLabels?.[0]?.name?.replace(/#/g, '')}</span> : '-';
        }
      }
    },
    {
      field: 'eventTitle',
      title: '标题',
      align: 'left',
      slots: {
        default: ({ row }) => {
          return renderFileJump(row, row.eventTitle);
        }
      }
    },
    {
      width: 100,
      field: 'postLevel',
      title: '风险等级',
      align: 'center',
      slots: {
        default: ({ row }) => {
          return row.riskLabel?.name ? (
            <span
              class="w-40px h-20px inline-flex align-center justify-center"
              style={{
                color: row.riskLabel?.color,
                backgroundColor: row.riskLabel?.bgColor
              }}
            >
              {row.riskLabel.name}
            </span>
          ) : (
            '-'
          );
        }
      }
    },
    {
      width: 200,
      field: 'source',
      title: '来源',
      align: 'center'
    }
  ]);

  return {
    columns
  };
}
